﻿using B.S.Ingredients.APIRead.Application.Command.SlaughterCommand;
using B.S.Ingredients.Domain;
using B.S.Ingredients.ErrorCode;
using B.S.Ingredients.Infartructrue.Interfaces;
using MediatR;

namespace B.S.Ingredients.APIRead.Application.CommandHandler.SlaughterHandler
{
    public class SlaughterFtCommandHandler : IRequestHandler<SlaughterFtCommand, APIResult<Slaughter>>
    {
        public SlaughterFtCommandHandler(IBaseRepository<Slaughter> slanughterRepository)
        {
            SlanughterRepository = slanughterRepository;
        }

        public IBaseRepository<Slaughter> SlanughterRepository { get; }

        public async Task<APIResult<Slaughter>> Handle(SlaughterFtCommand request, CancellationToken cancellationToken)
        {
            var path = SlanughterRepository.GetAll().FirstOrDefault(a => a.Productuin == request.Productuins);
            return new APIResult<Slaughter>
            {
                Code = ResultCode.success,
                Mag = "",
                Data = path
            };
        }
    }
}
